import Vue from 'vue'
import App from './App.vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    count: 0,
    list: [1,2,3,4,5,6,7,8,9]
  },
  mutations: {
    add(state) {
     state.count += 1
    },
    addCount (state, payload) {
      state.count += payload
     }
  },
  actions: {
    getAsyncCount(context, payload) {
      setTimeout(function(){
        // 一秒钟之后 要给一个数 去修改state
        context.commit('addCount', payload)
      }, 1000)
    }
  },
  getters: {
    filterList: state => state.list.filter(item => item > 5),
    token: state => state.user.token,
    name: state => state.setting.name
  },
  modules: {
    user: {
      namespaced: true,
      state: {
        token: '123456'
      },
      mutations: {
        updateToken(state) {
          state.token = 6780
        }
      }
    },
    setting: {
      state: {
        name: 'Brave-Y'
      }
    }

  }
})

Vue.config.productionTip = false

new Vue({
  render: h => h(App),
  store
}).$mount('#app')
